﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using 个人博客.entityClass;
using 个人博客.SqlViews;

namespace 个人博客.instrumentClass
{
    //注册
    public class registerClass
    {
        //注册
        public int Register(string Name, string Gmail, string Pwd) {
            using (var db = new Model1())
            {
                //账户表注册
                db.Blogs_Account.Add(Account(Name, Gmail, Pwd));
                db.SaveChanges();
                //获取自动生成的账号
                var list = db.Blogs_Account.FirstOrDefault(u => u.acc_gmail == Gmail);
                var a = list.acc_number;

                db.Blogs_Jurisdiction.Add(Jurisdiction(list.acc_number, 2));
                db.Blogs_personalInformation.Add(personalInformation(list.acc_number, Name, Gmail));
                db.SaveChanges();

                return a;
            }
        }
        //账户表注册
        private Blogs_Account Account(string Name, string Gmail, string Pwd) {
            return new Blogs_Account()
            {
                acc_gmail = Gmail,
                acc_pwd = Pwd,
                acc_name = Name
            };
        }
        //权限表注册
        private Blogs_Jurisdiction Jurisdiction(int number,int jurisdict/*(权限默认为2)*/)
        {
            return new Blogs_Jurisdiction()
            {
                jur_number = number,
                jur_jurisdict = jurisdict,
                jur_banned = "true",
                jur_warn = 0
            };
        }
        //个人信息表注册
        private Blogs_personalInformation personalInformation(int number,string name,string Gmail) {
            return new Blogs_personalInformation()
            {
                per_number = number,
                per_name = name,
                per_sex = "男",
                per_phone = "",
                per_gmail = Gmail,
                per_birthday  = "",
                per_site = ""
            };
        }
    }
}